"""
Test-02
"""
import yaml

def _flatmap(src, dest=None, prefix=''):
    """ 数据扁平化

    Args:
        src (dict): 需要处理的数据
        dest ([type], optional): 处理后装数据的容器
        prefix (str, optional): 用于传递拼接后的key
    """
    for _k, _v in src.items():
        if isinstance(_v, dict):
            _flatmap(_v, dest, f"{prefix}{_k}.") #递归调用
        else:
            dest.append((prefix+_k, _v ))

with open(r'02.list_dict_set\sample.yaml', mode='r', encoding='utf-8') as f:
    config = yaml.load(f, yaml.FullLoader)
    res = []
    _flatmap(config, dest=res)
    print(res)
